package demo.IOInputOutput;

import java.io.*;

/**
 * @Auther: hjy(lc))
 * @Date: 2022/8/15-08-15-10:05
 * @Description：demo.IOStream
 */
/*
    PrintWriter_use
        既可以包装字节流，也可以包装字符流
        一次写一行
        自动换行
 */
public class PrintWriter_use{
    public static void main(String[] args) {
        BufferedReader br = null;
        PrintWriter pw = null;

        try {
            br = new BufferedReader(new FileReader("a.txt"));

            pw = new PrintWriter(new FileWriter("a.txt"));
            //每次写一行数据
            pw.println('a');
            pw.println('b');
            pw.println('c');
            pw.println('d');
            pw.flush();

            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (br != null) {
                    br.close();
                }
                if (pw != null) {
                    pw.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
